﻿import QtQuick 2.0
import QtQuick.Controls 2.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import "./utils" as Utils


Rectangle {  
    property bool checkSceneStep: true
    property alias vehicleModel: vehicleListView.model
    property alias currentVehicleIndex: vehicleListView.currentIndex

    signal updateVehicleInfo(var currentVehicleInfo)
    signal connectVehicleSignal(string name, string type, string host)

    color: "#20212C"
    border.width: 0

    Image{
        x: 70
        y: 27
        source: "qrc:/imgs/search_icon.png"
        sourceSize.width: 18
        sourceSize.height: 18
    }

    Image{
        x: 337
        y: 19
        source: "qrc:/imgs/xg_icon.png"
        sourceSize.width: 117
        sourceSize.height: 25
    }

    Image{
        x: 480
        y: 10
        source: "qrc:/imgs/title_icon.png"
        sourceSize.width: 438
        sourceSize.height: 44
    }

    Rectangle{
        id: vehicleHeader
        anchors.horizontalCenter: parent.horizontalCenter
        y: 81
        width: 1246
        height: 54
        color: Qt.rgba(255,255,255,0.02)

        Text{
            x: 103
            anchors.verticalCenter: parent.verticalCenter
            text: "车辆名称"
            color: "#D9EDFF"
            font{
                family: "Microsoft YaHei"
                pixelSize: 24
            }
        }

        Text{
            x: 315
            anchors.verticalCenter: parent.verticalCenter
            text: "状态"
            color: "#D9EDFF"
            font{
                family: "Microsoft YaHei"
                pixelSize: 24
            }
        }

        Text{
            x: 1058
            anchors.verticalCenter: parent.verticalCenter
            text: "操作"
            color: "#D9EDFF"
            font{
                family: "Microsoft YaHei"
                pixelSize: 24
            }
        }
    }

    ListView{
        id: vehicleListView
        y: 135
        width: 1246
        height: 625
        anchors.horizontalCenter: parent.horizontalCenter
        orientation: ListView.Vertical
        clip: true
        focus: true

        ScrollBar.vertical: ScrollBar {
            id: scrollBar
        }

        delegate: VehicleInfoItem{
            dataModle: vehicleListView.model[index]
            width: 1246
            color: vehicleListView.currentIndex == index ? Qt.rgba(202, 223, 255, 0.1) : "#20212C"
            onConnect: {
                connectVehicleSignal(vehicleListView.model[index]["name"],
                                     vehicleListView.model[index]["type"],
                                     vehicleListView.model[index]["host"])
            }
            onSelect: {
                vehicleListView.currentIndex = index
                updateVehicleInfo(vehicleListView.model[vehicleListView.currentIndex])
            }
        }
    }

    Connections{
        target: vehicle_manager
        onSignalVehiclesInfo:{
            vehicleListView.model = JSON.parse(data)
            updateVehicleInfo(vehicleListView.model[vehicleListView.currentIndex])
        }
    }
}
